package com.ainote.controller;


import com.ainote.service.impl.BaiduAsrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/asr")
public class AsrController {

    @Autowired
    @Qualifier("baiduAsrService")
    private BaiduAsrService baiduAsrService;

    /**
     * 创建识别任务（长语音异步）
     */
    @PostMapping("/baidu")
    public Map<String, Object> startBaiduAsr(@RequestBody Map<String, String> body) throws Exception {
        String filePath = body.get("filePath"); // 例如 /uploads/xxx.wav
        if (filePath == null) throw new IllegalArgumentException("缺少 filePath");

        String taskId = baiduAsrService.createTask(filePath);
        return Map.of("taskId", taskId);
    }

    /**
     * 查询识别任务状态
     */
    @GetMapping("/status")
    public Map<String, Object> getStatus(@RequestParam String taskId) throws Exception {
        return baiduAsrService.queryTask(taskId);
    }
}
